<template>
<h1>猜数字练习</h1>
<input type="text" placeholder="请输入您猜的数字" v-model="guess">
<button @click="guessNum">猜一猜</button>
<h4>您猜的结果是:{{result}}</h4>
</template>


<script setup>
  import {ref} from "vue";
  let x = parseInt(Math.random()*100)+1;
  console.log("打个小炒:"+x);
  const guess = ref('');
  const result = ref('');

  const guessNum = ()=>{
    if(guess.value.trim()==''||isNaN(guess.value)){
      num.value = '';
      alert('请输入数字!');
      return;
    }
    if(guess.value>x){
      result.value = "您猜的数字太大了!";
    }else if(guess.value<x){
      result.value = "您猜的数字太小了!";
    }else{
      result.value = "恭喜您猜对了!";
    }
  }


</script>


<style scoped>

</style>